#include "trap.h"
#include "instr_def.h"
#include "instr_test.h"
    .set noreorder
    #.set noat
    .globl main
    .text
main:

    # SB 1
    li $k1, 0
    SB(0xccbbddaa, 0, 0x0) # [0x0] = 0xaa
    nop
    nop
    SB(0x11111111, 0, 0x0002) # [0x2] = 0x11
    nop
    nop
    SB(0x06278013, 0, 0x0003) # [0x3] = 0x13
    nop
    nop
    SB(0x44444444, 4, 0x0000) # [0x4] = 0x44
    nop
    nop
    SB(0x55555555, 4, 0x0001) # [0x5] = 0x55
    nop
    nop
    SB(0x88888888, 8, 0x0001) # [0x9] = 0x88
    nop
    nop
    SB(0x77ffffff, 8, 0x0003) # [0xb] = 0xff
    nop
    nop
    li $k1, 1

    # 0: aa __ 11 13
    # 4：44 55 __ __
    # 8：__ 88 __ ff

    # LB 2
    SLB_TEST(0xffffffaa, 0, 0) # [0x0] = 0xaa
    nop
    nop
    SLB_TEST(0x00000011, 0, 0x0002) # [0x2] = 0x11
    nop
    nop
    SLB_TEST(0x00000013, 0, 0x0003) # [0x3] = 0x13
    nop
    nop
    SLB_TEST(0x00000044, 4, 0x0000) # [0x4] = 0x44
    nop
    nop
    SLB_TEST(0x00000055, 4, 0x0001) # [0x5] = 0x55
    nop
    nop
    SLB_TEST(0xffffff88, 8, 0x0001) # [0x9] = 0x88
    nop
    nop
    SLB_TEST(0xffffffff, 8, 0x0003) # [0xb] = 0xff
    nop
    nop
    li $k1, 2

    # LBU 3
    LBU_TEST(0x000000aa, 0, 0x0000) # [0x0] = 0xaa
    nop
    nop
    LBU_TEST(0x00000011, 0, 0x0002) # [0x2] = 0x11
    nop
    nop
    LBU_TEST(0x00000055, 4, 0x0001) # [0x5] = 0x55
    nop
    nop
    LBU_TEST(0x00000088, 8, 0x0001) # [0x9] = 0x88
    nop
    nop
    LBU_TEST(0x000000ff, 8, 0x0003) # [0xb] = 0xff
    nop
    nop
    li $k1, 3

    # SH 4
    SH(0x33332334, 0x4, 0x0002) # [0x6] = 0x23 [0x7] == 0x34
    nop
    nop
    SH(0x12121256, 0xc, 0x0000) # [0xc] = 0x12 [0xd] == 0x56
    nop
    nop
    SH(0xeeffbbcc, 0x0, 0x0000) # [0x0] = 0xbb [0x1] == 0xcc
    nop
    nop
    # SH(0x12121256, 0xc, 0x0001) # AddressError
    nop
    nop
    # SH(0x12121256, 0x7, 0x0002) # AddressError
    nop
    nop
    li $k1, 4

    # 0: bb cc 11 13
    # 4：44 55 23 34
    # 8：__ 88 __ ff
    # c: 12 56 __ __

    # LH 5
    SLH_TEST(0x00001311, 0x0, 0x0002) # [0x2] = 0x11 [0x3] = 0x13
    nop
    nop
    SLH_TEST(0x00005544, 0x4, 0x0000) # [0x4] = 0x44 [0x5] = 0x55
    nop
    nop
    SLH_TEST(0xffffbbcc, 0x0, 0x0000) # [0x0] = 0xbb [0x1] = 0xcc
    nop
    nop
    # SLH_TEST(0x00000000, 0x4, 0x0001) # AddressError
    nop
    nop
    li $k1, 5
    
    # LHU 6
    LHU_TEST(0x00001311, 0x0, 0x0002) # [0x2] = 0x11 [0x3] = 0x13
    nop
    nop
    LHU_TEST(0x00005544, 0x4, 0x0000) # [0x4] = 0x44 [0x5] = 0x55
    nop
    nop
    LHU_TEST(0x0000bbcc, 0x0, 0x0000) # [0x0] = 0xbb [0x1] = 0xcc
    nop
    nop
    # LHU_TEST(0x00000000, 0x4, 0x0001) # AddressError
    nop
    nop
    li $k1, 6


    # SW 7
    SW(0x5678abcd, 0x10, 0x0000) # [0x10-0x13] = 0x5678abcd
    nop
    nop
    SW(0x80000000, 0x08, 0x0000) # [0x08-0x0c] = 0x80000000
    nop
    nop
    # SW(0x7fffffff, 0x0c, 0x0002) # AddressError
    nop
    nop
    li $k1, 7

    #  0: bb cc 11 13
    #  4：44 55 23 34
    #  8：80 00 00 00
    #  c: 12 56 __ __
    # 10: 56 78 ab cd

    # LW 6
    SLW_TEST(0x5678abcd, 0x4, 0x000c) # [0x10-0x13] = 0x5678abcd TEST ERROR
    nop
    nop
    SLW_TEST(0x80000000, 0x4, 0x0004) # [0x08-0x0c] = 0x80000000
    nop
    nop
    # SLW_TEST(0x00000000, 0x4, 0x0007) # AddressError
    nop
    nop
    # SLW_TEST(0x00000000, 0x1, 0x0000) # AddressError
    nop
    nop
    li $k1, 8

    # mix
    SB(0x7fffffff, 0x0, 0x0001) # [0x1] = 0xff 
    nop
    nop
    SH(0x66666677, 0x0, 0x0002) # [0x2] = 0x66 [0x3] = 0x77
    nop
    nop
    SLW_TEST(0x6677ffcc, 0x0, 0x0000)
    nop
    nop    
    SW(0xffffffff, 0xc, 0x0000) # [0xc-0xf] = ffffffff
    nop
    nop
    #  0: bb ff 66 77
    #  4：44 55 23 34
    #  8：80 00 00 00
    #  c: ff ff ff ff
    # 10: 56 78 ab cd
    SLH_TEST(0xffffffff, 0xc, 0x0000)
    nop
    nop
    LHU_TEST(0x0000ffff, 0xc, 0x0000)
    nop
    nop
    SLB_TEST(0x00000000, 0x8, 0x0002)
    nop
    nop
    LBU_TEST(0x00000080, 0x8, 0x0003)
    nop
    nop
    li $k1, 0x12345678 
    HIT_GOOD_TRAP		# stop temu

res_error: 
    li $s1, 0x11111111
    HIT_BAD_TRAP		# stop temu